define(function () {

    var self,content;
    var infoItem;

    function yspjinfo(){
        self = this;
        self._data = {
            pj: [],
            GWCS0004:'',//评价指标
            GWCS0005:'',//评价星数
            GWCS0006:'',//反馈建议
            GWCS0007:'',//照片地址
            GWCS0008:''//匿名否
        };
        self.pjzb = [];
        self.pjxs = [];
        self.imgArr = [];
        infoItem = app.pageParameters['yspjinfo_page'];//获取传的参数
        self.init();
    }

    //获取评价类型和星数
    yspjinfo.prototype.getStarData = function () {
        self._data.pj.splice(0,self._data.pj.length);
        app.ajax({
            xurl: "api/wx/gwat810/getMmrj",
            xdata: {
               MMRJ002:'2'
            },
            cb: function (result) {
                if (result.ok) {
                    for(var i=0;i<result.data.data.length;i++){
                        result.data.data[i].count = 0;
                    }
                    self._data.pj.pushArray(result.data.data);
                }
            }
        });
    };

    yspjinfo.prototype.initVue = function () {
        content = new Vue({
            el: doc.getElementById('content'),
            data: {
                item: infoItem,
                d:self._data,
                imgs: self.imgArr
            },
            methods:{
                pjChange: function (item, v) {
                    item.count = v;
                },
                submit:function () {
                    self.submit();
                },
                delimg: function (i) {
                    self.imgArr.removei(i);
                },
                addImgs: function () {
                    app.chooseImageNew(function (imgs) {
                        //self.imgArr.pushArray(imgs);
                        //app.extend(self.imgArr, imgs);
                        for (var i = 0; i < imgs.length; i++) {
                            self.imgArr.push({
                                img: imgs[i].img,
                                id: imgs[i].localId
                            })
                        }
                    });
                }
            }
        });
    }

    //提交
    yspjinfo.prototype.submit = function () {
        if(content.d.GWCW008){
            content.d.GWCW008 = 'Y';
        }else{
            content.d.GWCW008 = 'N';
        }
        for(var i=0;i<self._data.pj.length;i++){
            self.pjzb.push(self._data.pj[i].MMRJ001);
            self.pjxs.push(self._data.pj[i].count);
        }


        //app.showLoading();
        app.uploadLocalIds({
            ids:self.imgArr,
            cb:function (imgs) {
                content.d.GWCW004 = self.pjzb.join(',');//指标
                content.d.GWCW005 = self.pjxs.join(',');//星数
                //content.d.GWCW007 = imgs.join(',');//图片
                var imgurl = "";
                for (var i = 0; i < imgs.length; i++) {
                    imgurl += (imgs[i].name + ",");
                }
                content.d.GWCQ007=imgurl.substring(0,imgurl.length-1);
                var _xdata = app.extend(content.item,content.d);
                app.ajax({
                    xurl: "api/wx/gwat810/saveData",
                    loading: true,
                    xdata: {
                        obj: app.jsonString(_xdata)
                    },
                    cb: function (result) {
                        app.hideLoading();
                        if (result.ok) {
                            app.toast('提交成功！');
                            setTimeout(function () {
                                app.back(1);
                                app.pageModule('p_yspj')._refresh();
                            }, 300);
                        } else {
                            app.toast(result.data.message);
                        }
                    }
                });
            }
        });

    }


    yspjinfo.prototype.init = function () {
        self.getStarData();
        mui.ready(function () {
            self.initVue();
            mui('.mui-scroll-wrapper').scroll({
                deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
            });

        });
        mui('.icons').on('tap', 'i', function () {
            var index = parseInt(this.getAttribute("data-index"));
            var parent = this.parentNode;
            var children = parent.children;
            if (this.classList.contains("mui-icon-star")) {    //点击的那个之前如果由空心的星星变成实心的
                for (var i = 0; i < index; i++) {
                    children[i].classList.remove('mui-icon-star');   //star是空心的星星
                    children[i].classList.add('mui-icon-star-filled');  //filled是实心的黄色星星
                }
            } else {
                for (var i = index; i < 5; i++) {  //点击的那个之后由实心的星星变成空心的
                    children[i].classList.add('mui-icon-star')
                    children[i].classList.remove('mui-icon-star-filled')
                }
            }
        });
    }


    return new yspjinfo();

});